package org.loader.progressbarwithtext;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;

public class MainActivity extends Activity {
	private ProgressBarWithText mProgress;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mProgress = (ProgressBarWithText) findViewById(R.id.progress);
		mProgress.setMax(100);
		
		new MyAsyncTask().execute();
	}
	
	class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
		@Override
		protected Void doInBackground(Void... params) {
			for(int i=0;i<101;i++) {
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				publishProgress(i);
			}
			return null;
		}
		
		@Override
		protected void onProgressUpdate(Integer... values) {
			mProgress.setProgress(values[0]);
		}
	}
}
